<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>廉政告知书-登记</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/custom.form.css">
    <style type="text/css">
        .layui-disabled, .layui-disabled:hover {
            color: #000000 !important;
            cursor: not-allowed !important;
        }

        .layui-form-label {
            width: 100px;
        }

        .layui-input-block {
            margin-left: 130px;
        }

        .layui-input layui-unselect {
            cursor: pointer;
        }

        .layui-table {
            width: 96%;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header"></div>
                <div class="layui-card-body">
                    <div class="layui-tab table_div">
                        <ul class="layui-tab-title">
                            <li class="layui-this" id="unwrite">未填写</li>
                            <li id="write">已填写</li>
                        </ul>
                        <div class="layui-tab-content">
                            <div class="layui-tab-item layui-show">
                                <div class="layui-form-item">
                                    <div class="layui-input-inline">
                                        <input type="text" readonly class="layui-input" id="createTime" placeholder="立案时间">
                                    </div>
                                    <div class="layui-input-inline layui-form">
                                        <input type="text" class="layui-input" id="ajbh" placeholder="案件编号">
                                    </div>
                                    <button class="layui-btn" onclick="search()" id="search">查询</button>
                                </div>
                                <table class="layui-table" id="showTable" lay-filter="showTable"></table>
                            </div>
                            <div class="layui-tab-item">
                                <div class="layui-form-item"></div>
                                <table class="layui-table" id="showTable1" lay-filter="showTable1"></table>
                            </div>
                        </div>
                    </div>
                    <div id="writeDiv" class="demo-transfer" style="display: none">
                        <div class="layui-form" action="">
                            <div class="layui-form-item" style="margin-top: 5px">
                                <label class="layui-form-label" style=""></label>

                                <button type="button" class="layui-btn" id="upload">
                                    <i class="layui-icon">&#xe67c;</i>上传文件
                                </button>
                                <button type="button" class="layui-btn" id="viewButton">
                                    <i class="layui-icon">&#xe67c;</i>预览文件
                                </button>
                            </div>
                            <input id="url" hidden>
                            <div class="layui-form-item" style="margin-top: 5px">
                                <label class="layui-form-label" style="">廉政编号</label>
                                <div class="layui-input-block">
                                    <input rows="2" name="writeContent" id="writeContent"
                                           placeholder="请输入廉政编号" class="layui-input"></input>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/html" id="tool">
    <a class="layui-btn layui-btn-xs" lay-event="write">填写</a>
</script>
<script type="text/html" id="tool1">
    <a class="layui-btn layui-btn-xs" lay-event="viewfile">查看文件</a>
</script>

<script src="/layui/layui.all.js"></script>
<script src="/js/core.util.js"></script>
<script th:inline="none">
    // 获取token
    var token = CoreUtil.getData("access_token");
    // 地址栏转义token中的#号
    var tokenQuery = token.replace("#", "%23");
    var showTable1;
    var showTable;
    var table = layui.table;
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    var laydate = layui.laydate;
    var upload = layui.upload;
    var element = layui.element;
    var maxlength = 500;
    var inspectionMan = "";
    var mold = "";
    var contentdate = null;
    var startTime = null;
    var endTime = null;
    layui.use(['table', 'layer', 'laydate', 'upload', 'element'], function () {
        laydate.render({
            elem: '#createTime'
            , type: 'datetime'
            , range: '~'
            , done: function (value, date, endDate) {
                if (value !== null && value !== undefined && value !== "") {
                    startTime = value.split("~")[0];
                    endTime = value.split("~")[1];
                } else {
                    startTime = null;
                    endTime = null;
                }
            }
        });

        //执行实例
        var uploadInst = upload.render({
            elem: '#upload' //绑定元素
            , exts: 'xlsx|xls|pdf|docx|doc|tiff|bmp|jpg|jpeg|png|gif'
            ,
            url: '/sysFiles/upload?authorization=' + tokenQuery //上传接口
            , before: function (obj) {
                layer.msg('文件上传中...', {
                    icon: 16,
                    shade: 0.01,
                    time: 0
                })
            },
            done: function (res) {
                //上传完毕回调
                if (res.code === 0) {
                    layer.msg("文件上传成功！");
                    $('#viewButton').show();
                    $("#url").val(res.data.src);
                } else {
                    layer.msg(res.msg);
                }
            },
            error: function () {
                //请求异常回调
                layer.msg("上传失败!原因：" + res.msg);
                return false;
            }
        });
        showTable = table.render({
            elem: '#showTable',
            contentType: 'application/json',
            headers: {
                "authorization": token
            },
            url: '/workflow/notification/list0',
            method: 'post',
            request: {
                limitName: 'rows', //每页数据量的参数名，默认：limit
                pageName: 'page',
            },
            where: {},
            cols: [[
                {
                    align: 'center',
                    width: 230,
                    field: 'jcajxxuuid',
                    title: '检查UUID',
                    sort: true,
                    hide: true
                }, {
                    align: 'center',
                    width: 158,
                    field: 'jcajbh',
                    title: '检查案件编号',
                    sort: true,
                }, {
                    align: 'center',
                    width: 158,
                    field: 'ajmc',
                    title: '案件名称',
                    sort: true,
                }, {
                    align: 'center',
                    width: 158,
                    field: 'jcajbh',
                    title: '案件编号',
                    sort: true,
                }, {
                    align: 'center',
                    width: 158,
                    field: 'jcry',
                    title: '检查人员',
                    sort: true,
                }, {
                    align: 'center',
                    width: 158,
                    field: 'jcxm',
                    title: '检查项目',
                    sort: true,
                }, {
                    align: 'center',
                    width: 158,
                    field: 'nsrmc',
                    title: '纳税人名称',
                    sort: true,
                }, {
                    align: 'center',
                    width: 158,
                    field: 'nsrsbh',
                    title: '纳税人识别号',
                    sort: true,
                }, {
                    align: 'center',
                    width: 158,
                    field: 'larq',
                    title: '立案时间',
                    sort: true,
                }, {
                    fixed: 'right',
                    align: 'center',
                    width: 125,
                    toolbar: "#tool",
                    title: '操作'
                }

            ]],
            response: {
                statusName: 'result', //数据状态的字段名称，默认：code
                statusCode: 200, //成功的状态码，默认：0
                dataName: 'rows', //数据列表的字段名称，默认：data
                countName: 'total',//规定数据总数的字段名称，默认：count
            },
            page: true,
            parseData: function (res) {
                var dataList = res.data;
                var total = dataList.length; //请求的数据总数
                var list = []; //用来保存当前页显示的数据
                //前端模拟分页，获取当前页、分页显示数据量
                var page = $("#layui-table-page1").find(".layui-laypage-em").next().html();
                var limit = $("#layui-table-page1").find(".layui-laypage-limits select").val();
                console.log(page + ", " + limit);
                if (page == undefined || page == null || page == "") {
                    page = 1;
                }
                if (limit == undefined || limit == null || limit == "") {
                    limit = 10;
                }
                //数据从哪条数据开始
                var start = (page - 1) * limit;
                //数据从哪条数据结束
                var end = page * limit;
                if (end > total) {
                    end = total;
                }
                //取分页数据
                for (var i = start; i < end; i++) {
                    list.push(dataList[i]);
                }
                return {
                    "result": 200, //解析接口状态
                    "total": total, //解析数据长度
                    "rows": list //解析数据列表
                }
            }
        });

        /*
        // 未回访
        showTable = table.render({
            elem : '#showTable',
            contentType : 'application/json',
            headers : {
                "authorization" : token
            },
            page : true // 开启分页
            ,
            url : '/workflow/notification/list0' //数据接口
            ,
            method : 'POST',
            parseData : function(res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code" : res.code, //解析接口状态
                    "msg" : res.msg, //解析提示文本
                    "count" : CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data" : CoreUtil.isEmpty(res.data) ? null
                            : CoreUtil.paramsDecrypt(res.data.records)
                }
            },

            cols : [ [
                      {
                          align : 'center',
                          width : 230,
                          field : 'jcajxxuuid',
                          title : 'JCAJXXUUID',
                          sort : true,
                          hide : true
                      }, {
                          align : 'center',
                          width : 205,
                          field : 'jcajbh',
                          title : '稽查案件编号',
                          sort : true,
                      }, {
                            align : 'center',
                            width : 210,
                            field : 'nsrsbh',
                            title : '纳税人识别号',
                            sort : true,
                      }, {
                            align : 'center',
                            width : 280,
                            field : 'nsrmc',
                            title : '纳税人名称',
                            sort : true,
                      }, {
                          align : 'center',
                          width : 200,
                          field : 'jtzfrq',
                          title : '检查通知书销号日期',
                          sort : true,
                      }, {
                          align : 'center',
                          width : 200,
                          field : 'zxwbrq',
                          title : '执行完毕日期',
                          sort : true,
                      }, {
                            fixed : 'right',
                            align : 'center',
                            width : 95,
                            toolbar : "#tool",
                            title : '操作'
                      },
                      ] ],
            toolbar : '#logToolbar'
        }); */

        // 列操作
        table.on('tool(showTable)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'write':
                    var _jcajxxuuid = data.jcajxxuuid;
                    $('#viewButton').hide();
                    $('#url').val("");
                    layer.open({
                        type: 1,
                        offset: '50px',
                        skin: 'layui-layer-molv',
                        title: "廉政通知书录入",
                        area: ['700px', '320px'],
                        shade: 0,
                        shadeClose: false,
                        content: jQuery("#writeDiv"),
                        btn: ['确认', '取消'],
                        yes: function (index) {
                            var writeContent = $('#writeContent').val();
                            if (CoreUtil.isEmpty(writeContent)) {
                                layer.msg("廉政编号没有填写!");
                                return false;
                            }
                            var url = $('#url').val();
                            if (CoreUtil.isEmpty(url)) {
                                layer.msg("文件没有上传!");
                                return false;
                            }
                            var mapArr = {
                                'relevance': _jcajxxuuid,
                                'notificationFile': url,
                                'notificationNo': writeContent,
                            };
                            CoreUtil.sendPost("/workflow/notification/write", mapArr,
                                function (res) {
                                    if (res.code === 0) {
                                        layer.msg("成功 ！");
                                        search();
                                        search1();
                                        return false;
                                    } else {
                                        layer.msg(res.msg);
                                        return false;
                                    }
                                });
                            layer.close(index);
                        }
                    });
                    break;
            }
        });
        // 列操作
        table.on('tool(showTable1)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'view':
                    view(data, "0");
                    break;
            }
        });
        // 已回访
        showTable1 = table.render({
            elem: '#showTable1',
            contentType: 'application/json',
            headers: {
                "authorization": token
            },
            page: true // 开启分页
            ,
            url: '/workflow/notification/list1' //数据接口
            ,
            method: 'POST',
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": CoreUtil.isEmpty(res.data) ? 0 : res.data.total, //解析数据长度
                    "data": CoreUtil.isEmpty(res.data) ? null
                        : CoreUtil.paramsDecrypt(res.data.records)
                }
            },

            cols: [[
                {
                    align: 'center',
                    width: 230,
                    field: 'jcajxxuuid',
                    title: 'JCAJXXUUID',
                    sort: true,
                    hide: true
                }, {
                    align: 'center',
                    width: 140,
                    field: 'notificationNo',
                    title: '廉政编号',
                    sort: true,
                }, {
                    align: 'center',
                    width: 205,
                    field: 'jcajbh',
                    title: '稽查案件编号',
                    sort: true,
                }, {
                    align: 'center',
                    width: 210,
                    field: 'nsrsbh',
                    title: '纳税人识别号',
                    sort: true,
                }, {
                    align: 'center',
                    width: 280,
                    field: 'nsrmc',
                    title: '纳税人名称',
                    sort: true,
                }, {
                    align: 'center',
                    width: 200,
                    field: 'createId',
                    title: '填写人',
                    sort: true,
                }, {
                    align: 'center',
                    width: 200,
                    field: 'notificationFile',
                    title: 'notificationFile',
                    sort: true,
                    hide: true,
                }, {
                    fixed: 'right',
                    align: 'center',
                    width: 125,
                    toolbar: "#tool1",
                    title: '操作'
                }
            ]],
            // toolbar : '#logToolbar'
        });

        // 列操作

        table.on('tool(showTable1)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'viewfile':
                    window.open(data.notificationFile, '_blank');
                    break;
            }
        });

        // 返回
        $("#btn_cancel").click(function () {
            back();
            return false;
        });

    });

    function search() {
        showTable.reload({
            where: {
                startTime: startTime,
                endTime: endTime,
                ajbh: $("#ajbh").val()
            },
            page: {
                curr: 1
            }
        });
    }

    function search1() {
        showTable1.reload({
            where: {},
            page: {
                curr: 1
            }
        });
    }

    function back() {
        search();
        $(".table_div").show();
        $(".operation").hide();
    }

    $("#unwrite").click(function () {
        search();
    });

    $("#write").click(function () {
        search1();
    });
    $("#viewButton").click(function () {
        var url = $("#url").val();
        window.open(url, '_blank');
    });

</script>

</body>
</html>